package com.smart.framework.util;

/**
 * <p><b>Description:</b>  TODO
 * <p><b>Company:</b>
 *
 * @author created by Jesse Xu at 16:21 on 2019/10/29
 * @version V0.1
 * @classNmae ByteUtils
 */
public class ByteUtils {

    public static int bytes2Int(byte[] b,int start,int len){
        int sum =0;
        int end = start+len;
        for (int i=start;i<end;i++){
            int n=((int)b[i])&0xff;
            sum=n+sum;
        }
        return sum;
    }
    public static String byteToHex(byte[] bytes) {
        StringBuilder sign = new StringBuilder();
        for (int i = 0; i < bytes.length; i++) {
            String hex = Integer.toHexString(bytes[i] & 0xFF);
            if (hex.length() == 1) {
                sign.append("0");
            }
            sign.append(hex.toUpperCase());
        }
        return sign.toString();

    }
}
